﻿<?php
defined('IN_DESTOON') or exit('Access Denied');
$table = $DT_PRE.'sx';
$menus = array (
    array('添加属性', '?moduleid='.$moduleid.'&file='.$file.'&action=add'),
    array('属性列表', '?moduleid='.$moduleid.'&file='.$file.'&action='),
    array('更新属性缓存', '?moduleid='.$moduleid.'&file='.$file.'&action=cache')
);
$fd = $data = array();
$fd = array('name','pid','catid','is_search');
$datalist = cache_read('sx.php','sell');
$_category = cache_read('category-5.php');//供应分类
switch($action) {
	case 'add':
		if($submit) 
		{	
			$pid = $pid ? $pid : 0;
			if(strpos($name, "\n") === false) {
				$db->query("insert into $table (`name`,`pid`,`catid`) values ('".$name."','".$pid."','".$catid."')");
			}
			else{
				$a = explode("\n",$name);
				foreach($a as $cc)
				{
				$db->query("insert into $table (`name`,`pid`,`catid`) values ('".$cc."','".$pid."','".$catid."')");
				}
			}
			dmsg('添加成功', '?moduleid='.$moduleid.'&file='.$file.'&action=add');
		} 
		else 
		{
			include tpl('sx/insert', $module);
		}
	break;
	case 'edit':
		if($submit) 
		{	
			$pid = $pid ? $pid : 0;
			$db->query("update $table set `name` = '".$name."',`pid`='".$pid."',`catid`='".$catid."' where id=".$id);
			dmsg('修改成功', '?moduleid='.$moduleid.'&file='.$file.'&action=');
		} 
		else 
		{
			
			include tpl('sx/edit', $module);
		}
	break;
	case 'cache':
		
		$result = $db->query("SELECT * FROM {$table} order by listorder");
		while($r = $db->fetch_array($result)) {
			$data[$r['id']] = $r;
		}	
		cache_write('sx.php',$data,'sell');
		dmsg('更新成功', '?moduleid='.$moduleid.'&file='.$file.'&action=');
	break;
	case 'zfl':
		include tpl('sx/indexz', $module);
	break;
	default:
		include tpl('sx/index', $module);
	break;
}
?>